<template>
	<view class="user-container">
		<!-- 个人信息 -->
		<view class="header">
			<view class="header-img">
				<image :src="avatarUrl" mode=""></image>
			</view>
			<view class="btn-login" @click="goToLogin">
				<text type="default">{{userInfo.nickName?userInfo.nickName:'点击登录'}}</text>
			</view>
		</view>
		<!-- 店铺统计 -->
		<view class="count-container">
			<view class="collect">
				<text>收藏店铺</text>
			</view>
			<view class="collect">
				<text>收藏商品</text>
			</view>
			<view class="collect">
				<text>关注商品</text>
			</view>
			<view class="collect">
				<text>我的足迹</text>
			</view>
		</view>

		<!-- 我的订单 -->
		<view class="order-container">
			<view class="my-order">
				我的订单
			</view>
			
			<view class="more">
				<view  class="order-item">
					<view class="order-icon obligation">
						<image src="../../static/images/order/obligation.png" mode=""></image>
					</view>
					<view class="all-order">
						待付款
					</view>
				</view>
				<view class="order-item">
					<view class="order-icon no-receiving">
						<image src="../../static/images/order/no-receiving.png" mode=""></image>
					</view>
					<view class="all-order">
						待收货
					</view>
				</view>
				<view class="order-item">
					<view class="order-icon">
						<image src="../../static/images/order/returned.png" mode=""></image>
					</view>
					<view class="all-order">
						待归还
					</view>
				</view>
				<view class="order-item">
					<view class="order-icon">
						<image src="../../static/images/order/all-order.png" mode=""></image>
					</view>
					<view class="all-order">
						全部订单
					</view>
				</view>
			</view>
		</view>
		<!-- 收货地址 -->
		<view class="common ">
			收货地址
		</view>
		<!-- 联系客服 -->
		<view class="common ">
			联系客服
		</view>
		<!-- 意见反馈 -->
		<view class="common ">
			意见反馈
		</view>
		<!-- 退出登录 -->
		<view class="common login" @click="quit" v-if="userInfo.nickName">
			退出登录
		</view>
	</view>
</template>

<script>
	const defaultAvatarUrl =
		'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

	export default {
		data() {
			return {
				avatarUrl: defaultAvatarUrl,
				userInfo: {},
			}
		},

		mounted() {
			uni.getStorage({
				key: 'userInfo',
				success: (res) => {
					console.log(res);
					this.userInfo = res.data;
					this.avatarUrl = res.data.avatarUrl;
				},

			})
		},
		methods: {

			// 跳转到Login页面
			goToLogin() {
				if (this.userInfo.nickName) {
					return;
				}
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			// 退出登录
			quit(){
				uni.showModal({
					content:'您确定要退出吗？',
					success:(res) => {
						if(res.confirm){
							uni.clearStorage();
							uni.reLaunch({
								url:'/pages/user/user'
							});
						}
					}
				})
			}
		},
	}
</script>

<style lang="scss">
	.user-container {
		width: 100vw;
		height: 100vh;
		background: #f4f4f4;
		.header {
			display: flex;
			align-items: center;
			margin-bottom: 10rpx;
			padding: 0 20rpx;
			height: 200rpx;
			background-color: #fff;
			.header-img {
				margin-right: 20rpx;
				width: 100rpx;
				height: 100rpx;
				border-radius: 999rpx;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}
		.count-container{
			display: flex;
			align-items: center;
			margin: 0 20rpx;
			background: #fff;
			height: 120rpx;
			.collect{
				width: 25%;
				text-align: center;
				font-size: 24rpx;
				color: #414244;
			}
		}
		.order-container{
			margin: 10rpx 20rpx;
			background: #fff;
			.my-order{
				margin: 0 10rpx;
				padding: 20rpx 0;
				height: 40rpx;
				line-height: 40rpx;
				border-bottom: 1rpx solid #eadfdf;
				font-size:28rpx;
			}
			.more{
				display: flex;
				align-items: center;
				height: 150rpx;
				.order-item{
					width: 25%;
					display: flex;
					flex-direction: column;
					align-items: center;
					font-size: 24rpx;
					.order-icon{
						image{
							width: 64rpx;
							height: 64rpx;
							
						}
						&.no-receiving{
							// margin-top: 5rpx;
						}
						&.obligation{
							transform: translateY(-3rpx);
						}
					}
					
				}
			}
		}
		.common{
			margin: 0 20rpx 10rpx;
			padding:0 10rpx;
			height:80rpx;
			line-height: 80rpx;
			font-size:28rpx;
			background:#fff;
			&.login{
				text-align: center;
				color:#fff;
				background-color: orangered;
			}
		}
	}
</style>
